package com.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class ALifeCycleActivity extends Activity {
	public static ALifeCycleActivity	instance;
	public static Context		content;

	public ALifeCycleActivity() {
		Log.e("Activity", "构造");
	}

	//static不会被销毁
	public static Object o1=null;
	public Object o2=null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		Log.e("Activity", "onCreate");
		super.onCreate(savedInstanceState);
		instance = this;
		content = this;
		setContentView(new SvLifecycle(this));
		if(o1==null){
			o1=new Object();
			Log.e("--Object1--", "构造");
		}
		if(o2==null){
			o2=new Object();
			Log.e("--Object2--", "构造");
		}
	}

	protected void onStart() {
		Log.e("Activity", "onStart");
		super.onStart();
	}

	protected void onResume() {
		Log.e("Activity", "onResume");
		super.onResume();
	}

	protected void onPause() {
		Log.e("Activity", "onPause");
		super.onPause();
	}

	protected void onRestart() {
		Log.e("Activity", "onRestart");
		super.onRestart();
	}

	protected void onStop() {
		Log.e("Activity", "onStop");
		super.onStop();
	}

	protected void onDestroy() {
		Log.e("Activity", "onDestroy");
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.i("Activity", "key=" + keyCode);
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new AlertDialog.Builder(this).setTitle("温馨提示").setMessage("确认退出？").setPositiveButton("确定", new AlertDialog.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					System.exit(0);// 正常退出游戏
				}
			}).setNegativeButton("取消", new AlertDialog.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			}).show();
			return false;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}
}